package com.xzbd.springbootmybatiesdm.config;

import javax.servlet.MultipartConfigElement;

import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;

/**  
 * 文件上传配置  
 * @return  
 */ 
@Configuration
public class FileUploadSizeConfig{

    @Bean  
    public MultipartConfigElement multipartConfigElement() {  
        MultipartConfigFactory factory = new MultipartConfigFactory();  
        int max = 100;
        //单个文件最大  
        factory.setMaxFileSize(DataSize.of(max, DataUnit.MEGABYTES)); //MB  
        /// 设置总上传数据总大小  
        factory.setMaxRequestSize(DataSize.of(10 * max, DataUnit.MEGABYTES));  
        return factory.createMultipartConfig();  
    }  
}